<?php
/**
 * Created by 荣耀电竞.
 * User: 林子彦 <278805354@qq.com>
 * Date: 2018/6/12 0012
 * Time: 10:24
 */
namespace App\Shop\Controllers;
use App\Base\Controllers\Controller;
use App\Shop\Contracts\GoodsClassInterface;
use Illuminate\Http\Request;


class AdminGoodsClassController extends Controller
{
    /**
     * 获取产品操作
     * @return GoodsClassInterface
     */
    public function getGoodsClassInterface(){
        return app()->make(GoodsClassInterface::class);
    }
   public function index(){
       $menuList=$this->getGoodsClassInterface()->getGoodsClassList([]);
       $menuArr=array();
       foreach ( $menuList as $k=> $item) {
           $menuArr[$k]["id"]=$item->id;
           $menuArr[$k]["name"]=$item->name;
           $menuArr[$k]["pId"]=$item->pid;
       }
       return view("shop.class.index")->with("menu_list",json_encode($menuArr));
   }
   public function classSelectMenus(){
       $menuList=$this->getGoodsClassInterface()->getGoodsClassList([]);
       $menuArr=array();
       foreach ( $menuList as $k=> $item) {
           $menuArr[$k]["id"]=$item->id;
           $menuArr[$k]["name"]=$item->name;
           $menuArr[$k]["pId"]=$item->pid;
       }
       return view("admin.config.show_select_menus")->with("menu_list",json_encode($menuArr));
   }

    /***
     * 产品分类添加
     */
   public function save(Request $request){
       return $this->getGoodsClassInterface()->updateOrCreateConfigClassData($request->all());
   }

    /**
     * 产品分类编辑
     */
   public function edit(Request $request){
       return $this->getGoodsClassInterface()->getGoodsClassInfo($request->all());
   }

    /***
     * 商品分类删除
     * @param Request $request
     * @return mixed
     */
   public function del(Request $request){
       return $this->getGoodsClassInterface()->delGoodsClass($request->all());
   }
}